using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PatchMakingTool
{
    public partial class UCSelectFolder : UserControl
    {
        private string _folderPath = string.Empty;

        public string FolderPath
        {
            get { return _folderPath; }
            set
            {
                if (Directory.Exists(value))
                {
                    _folderPath = value;
                    this.textBoxPath.Text = _folderPath;
                    this.folderBrowserDialog.SelectedPath = _folderPath;
                    OnFolderSelected(new FolderSelectedEventArgs(_folderPath));
                }
            }
        }

        public UCSelectFolder()
        {
            InitializeComponent();
        }

        public event EventHandler<FolderSelectedEventArgs> FolderSelected;

        protected virtual void OnFolderSelected(FolderSelectedEventArgs e)
        {
            if (FolderSelected != null) FolderSelected(this, e);
        }

        private void buttonBrowser_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                FolderPath = folderBrowserDialog.SelectedPath;
            }
        }

        public void Reset()
        {
            this.textBoxPath.Text = string.Empty;
            OnFolderSelected(new FolderSelectedEventArgs(string.Empty));
        }
    }

    public class FolderSelectedEventArgs : System.EventArgs
    {
        public readonly string FolderPath;

        public FolderSelectedEventArgs(string folderPath)
        {
            FolderPath = folderPath;
        }
    }
}
